#!/usr/bin/env python
# coding:utf-8

import unittest
from mock import Mock
from sql_rice.gui.method_wrapper import MethodWraper
from sql_rice.utils import  always_false, do_nothing


class ProxyTest(unittest.TestCase):

    def test_raise_invalid(self):
        validation = {'nombre': always_false}
        w = MethodWraper(do_nothing, validation, do_nothing)
        self.assertRaises(ValueError, w, nombre='jacinto', edad='a2s5')

    def test_raise_missing(self):
        validation = {'mising': do_nothing}
        w = MethodWraper(do_nothing, validation, do_nothing)
        self.assertRaises(KeyError, w, nombre='koke')

    def test_call_ok(self):
        method = Mock()
        w = MethodWraper(method, {}, do_nothing)
        w(nombre='jacinto', edad=45)
        method.assert_called_once_with(nombre='jacinto', edad=45)
